package com.wanmait.community.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.community.entity.AccessRecord;
import com.wanmait.community.service.AccessRecordService;
import com.wanmait.community.service.CarService;
import com.wanmait.community.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("Access")
public class AccessRecordController {


    @Resource
    private AccessRecordService accessRecordService;
    @Resource
    private CarService carService;
    @PostMapping("add")
    public AjaxResult add(@RequestBody AccessRecord accessRecord,Integer pageNum) {
        Integer pageSize = 6;
        PageInfo<AccessRecord> pageInfo = accessRecordService.findByPage(accessRecord,pageNum, pageSize);
        return AjaxResult.success().put("pageInfo", pageInfo);

    }
    @DeleteMapping("{id}")
    public AjaxResult delete(@PathVariable Integer id) {
        accessRecordService.delete(id);
        return AjaxResult.success();
    }

    @GetMapping("handlelist")
    public AjaxResult handlelist() {
       List handle =  carService.handlelist();
        return AjaxResult.success().put("handlelist", handle);
    }

    @PostMapping("handleinsert")
    public AjaxResult handleinsert( @RequestBody AccessRecord accessRecord) {
        System.out.println(accessRecord);
        accessRecordService.handleinsert(accessRecord);
        return AjaxResult.success();
    }

}
